package system

import (
	"parking-lot-go-dingding/model"
	"time"
)

type DingtalkSystemCorpMoneyLogStruct struct {
	Id            int       `json:"id" gorm:"type:int(11) auto_increment; NOT NULL; primary_key"`
	CorpId        string    `json:"corp_id" gorm:"type:varchar(50); NOT NULL;  COMMENT:'企业id'"`
	MemberId      int       `json:"member_id" gorm:"type:int(11); COMMENT:'会员id'"`
	Type          int       `json:"type" gorm:"type:tinyint(1); NOT NULL; COMMENT:'变动类型 1增 2减'"`
	RealName      string    `json:"real_name" gorm:"type:varchar(20);  COMMENT:'会员名称'"`
	Mobile        string    `json:"mobile" gorm:"type:varchar(20);  COMMENT:'手机号码'"`
	Cars          string    `json:"cars" gorm:"type:text; COMMENT:'车牌号'"`
	Money         float64   `json:"money" gorm:"type:decimal(10,2); NOT NULL; COMMENT:'变动金额'"`
	Desc          string    `json:"desc" gorm:"type:varchar(255);  COMMENT:'描述'"`
	OperationType int       `json:"operation_type" gorm:"type:tinyint(1); COMMENT:'操作类型 1新增 2修改 3删除'"`
	BeforeMoney   float64   `json:"before_money" gorm:"type:decimal(10,2); NOT NULL; COMMENT:'变动之前余额'"`
	AfterMoney    float64   `json:"after_money" gorm:"type:decimal(10,2); NOT NULL; COMMENT:'变动之后余额'"`
	CreatedAt     time.Time `json:"created_at" gorm:"type:datetime"`
	UpdatedAt     time.Time `json:"updated_at" gorm:"type:datetime"`
}

func (c *DingtalkSystemCorpMoneyLogStruct) TableName() string {
	return "dingtalk_system_corp_money_log"
}

func (c *DingtalkSystemCorpMoneyLogStruct) List(where map[string]interface{}) ([]DingtalkSystemCorpMoneyLogStruct, error) {

	var list []DingtalkSystemCorpMoneyLogStruct

	//查询条件
	db := model.Db

	if err := db.
		Table(c.TableName()).
		Where(where).
		Order("id desc").
		Scan(&list).Error; err != nil {
		return nil, err
	}

	return list, nil
}

func (c *DingtalkSystemCorpMoneyLogStruct) Count(where map[string]interface{}) (int64, error) {
	var count int64

	if err := model.Db.Table(c.TableName()).Where(where).Count(&count).Error; err != nil {
		return 0, err
	}
	return count, nil
}
